/**
 * 27. Remove Element
 * https://leetcode.com/problems/remove-element/
 */
package lc27;

public class Main {
  public static void main(String[] args) {
    int[] nums = {3,2,2,3};
    int val = 3;
    int len = new Solution().removeElement(nums, val);
    System.out.println(len);
    for (int i = 0; i < len; i++) {
      System.out.print(nums[i] + " ");
    }
  }
}

class Solution {
  public int removeElement(int[] nums, int val) {
    int cursor = 0;
    for (int i = 0; i < nums.length; i++) {
      if (nums[i] != val) {
        nums[cursor++] = nums[i];
      }
    }
    return cursor;
  }
}
